using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using System.Data;

namespace CheckConnection
{
    class CheckConnection
    {
        string serverName, database;
        bool resultServer, resultDB;

        public string Database
        {
            get { return database; }
            set { database = value; }
        }

        public string ServerName
        {
            get { return serverName; }
            set { serverName = value; }
        }

        public bool ResultServer
        {
            get { return resultServer; }
            set { resultServer = value; }
        }

        public bool ResultDB
        {
            get { return resultDB; }
            set { resultDB = value; }
        }

        public void CheckCnn()
        {
            string cnnString = String.Format(@"Data Source={0};Integrated Security=true;Connect Timeout=2", serverName);
            SqlConnection cn = new SqlConnection(cnnString);
            try
            {
                cn.Open();
                resultServer = true;
            }
            catch(DataException ex)
            {
                
                resultServer = false;
            }
        }

        public void checkDatabase()
        {
            string cnnString = String.Format(@"Data Source={0};Initial Catalog={1};Integrated Security=true", serverName, database);
            SqlConnection cn = new SqlConnection(cnnString);
            try
            {
                cn.Open();
                resultDB = true;
            }
            catch
            {
                resultDB = false;
            }
        }
    }
}
